//
//  StartPageController.m
//  OneBox
//
//  Created by dev on 16/1/18.
//  Copyright © 2016年 donglian@eastunion.net. All rights reserved.
//

#import "StartPageController.h"
#import "SetIPController.h"
#import "MainController.h"

@interface StartPageController ()

@property (weak, nonatomic) IBOutlet UIImageView *startPageView;

@end

@implementation StartPageController



- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBarHidden = YES;
    
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *textIP = [defaults objectForKey:@"IP"];
    
    
    
    // 设置一个默认的IP
    if (textIP.length == 0) {
    
        NSString *defaultIP = @"124.207.197.43";
        [defaults setObject:defaultIP forKey:@"IP"];
        
        textIP = [defaults objectForKey:@"IP"];
        
    }
    // 判断IP是否存在
    if (textIP){
        
        double delay = 3.0;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            UIStoryboard * mainStoryBoard =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
            MainController *mc = [mainStoryBoard instantiateViewControllerWithIdentifier:@"MainController"];
            mc.IPStr = textIP;
            [self.navigationController pushViewController:mc  animated:YES];
        });
        
    }
    else{
        // 1.延时2秒后进入下一个页面
        double delay = 3.0;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            UIStoryboard * mainStoryBoard =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
            SetIPController *sc = [mainStoryBoard instantiateViewControllerWithIdentifier:@"SetIPController"];
            [self.navigationController pushViewController:sc  animated:YES];
        });
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
